package com.bmps.springcloud.insuredmicroservice.service.underwrite.strategy.insurance;

import com.bmps.springcloud.insuredmicroservice.config.accept.ProductConfig;
import com.bmps.springcloud.insuredmicroservice.constant.accept.AcceptConstant;
import com.bmps.springcloud.insuredmicroservice.constant.accept.UnderWriteConstant;
import com.bmps.springcloud.insuredmicroservice.model.accept.resquest.*;
import com.bmps.springcloud.insuredmicroservice.model.underwrite.InsuredModel;
import com.bmps.springcloud.insuredmicroservice.repository.underwrite.coresystem.InsuredCoreRepository;
import com.bmps.springcloud.insuredmicroservice.util.accept.AcceptUtil;
import org.apache.commons.lang3.StringUtils;

import java.util.List;

/**
 * 投核保校验  投核保通用校验
 *
 * @author: Jacob
 * @date 2020-04-06 16:30:40
 */
public class BaseInsuranceStrategy implements InsuranceStrategy {

    @Override
    public InsuredModel checkInsuredRolesByRiskCode(AcceptRequestDataModel acceptRequestDataModel, InsuredCoreRepository insuredCoreRepository,
                                                    ProductModel productModel, ProductConfig productConfig) {
        RequestModel requestModel = acceptRequestDataModel.getRequest();
        CustInfoModel custInfoModel = requestModel.getCustInfo();
        //被保人信息
        List<InsurantModel> insurantModelList = custInfoModel.getInsurants().getInsurant();
        InsurantModel insurantModel = AcceptUtil.getInsurantModelBySeq(productModel.getProdInsSeq(), insurantModelList);

        String type = insurantModel.getOccupationType();
        //与投保人的关系
        String relation = insurantModel.getRelToApp();

        //校验投保人和被保人的关系
        if (!(productConfig.getRelationList().contains(insurantModel.getRelToApp()))) {
            return AcceptUtil.getInsuredResponse(UnderWriteConstant.UNDER_WRITE_FIAL_CODE,
                    UnderWriteConstant.UNDER_WRITE_NUGG0007_MESSAGE);
        }

        //职业类别不能为1-4类
        if (!AcceptConstant.OCCUPATION_ONE_TO_FOUR.contains(type)) {
            return AcceptUtil.getInsuredResponse(UnderWriteConstant.UNDER_WRITE_FIAL_CODE, String.format(UnderWriteConstant.UNDER_WRITE_NPGG0016_MESSAGE, type));
        }

        //被保人理赔标识
        if (insurantModel.getClaimFlag() > 0) {
            return AcceptUtil.getInsuredResponse(UnderWriteConstant.UNDER_WRITE_NUGG0027,
                    String.format(UnderWriteConstant.UNDER_WRITE_NUGG0027_MESSAGE, insurantModel.getName()));
        }

        //黑名单
        if (insurantModel.getBlackListFlag() > 0) {
            return AcceptUtil.getInsuredResponse(UnderWriteConstant.UNDER_WRITE_NUGG0031,
                    String.format(UnderWriteConstant.UNDER_WRITE_NUGG0031_MESSAGE, insurantModel.getName()));
        }

        return AcceptUtil.getInsuredResponse(AcceptConstant.RESULT_SUCCESS_CODE, AcceptConstant.RESULT_SUCCESS_MESSAGE);
    }
}
